<template>
  <div class="login-wrap">
    <div class="ms-login">
      <div class="ms-title">管理员登录</div>
      <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
        <el-form-item prop="username">
          <el-input v-model="param.username" placeholder="用户名"> </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" placeholder="密码" v-model="param.password" show-password>
          </el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm" round>登录</el-button>
        </div>
        <div class="studentlogin-btn">
          <el-button type="primary" @click="studentsubmit" round plain>学生登录点这里</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import request from "../helper/request.js";

export default {
  data() {
    return {
      param: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    async submitForm() {
      await this.$refs.login.validate((valid) => {
        if (valid) {
          request
            .post("/loginAdmin", {
              adminName: this.param.username,
              password: this.param.password
            }, {
              headers: {
                'Content-Type': 'multipart/form-data'
              }
            })
            .then((res) => {
              console.log(res);
              if(res.code === 200) {
                this.$message.success("登录成功");
                this.$router.push("/ManageHome");
              }else {
                this.$message.error("错误，请重新输入！");
              }
            });
        } else {
          alert("错误，请重新输入！");
        }
      });
    },
    studentsubmit() {
      this.$router.push("/StudentLogin");
    }
  },
};
</script>

<style scoped>
.login-wrap {
  height: 97.6vh;
  background: #9cd6fa;
}

.ms-title {
  width: 100%;
  line-height: 50px;
  text-align: center;
  font-size: 25px;
  color: #23a3b7;
  border-bottom: 1px solid #23a3b7;
}

.ms-login {
  position: absolute;
  left: 48%;
  top: 50%;
  width: 400px;
  padding: 40px;
  margin: -190px 0 0 -175px;
  border-radius: 5px;
  background: #e0f1fc;
  box-shadow: 0 15px 25px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.ms-content {
  padding: 30px 30px;
}

.login-btn {
  text-align: center;
}

.studentlogin-btn {
  text-align: center;
}

.studentlogin-btn button {
  width: 100%;
  height: 36px;
  margin-top: 30px;
}

.login-btn button {
  width: 100%;
  height: 36px;
  margin-top: 10px;
}
</style>